package org.hako.recite.word.test.impl;

import java.util.Iterator;

/**
 * Range implement of {@link TestWordIndexSet}.
 * 
 * @author xnnyygn
 */
public class RangeTestWordIndexes implements TestWordIndexes {

    private int leftLimit;
    private int rightLimit;

    /**
     * Create
     * 
     * @param rightLimit 
     */
    public RangeTestWordIndexes(int rightLimit) {
        this(0, rightLimit);
    }

    /**
     * Create
     * 
     * @param leftLimit
     * @param rightLimit 
     */
    public RangeTestWordIndexes(int leftLimit, int rightLimit) {
        super();
        this.leftLimit = leftLimit;
        this.rightLimit = rightLimit;
    }

    @Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {

            private int current = leftLimit;

            @Override
            public boolean hasNext() {
                return current < rightLimit;
            }

            @Override
            public Integer next() {
                return current++;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        };
    }

    @Override
    public int count() {
        return rightLimit - leftLimit;
    }
}
